package com.example.demo.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.pojo.MV;
import com.example.demo.pojo.Singer;
import com.example.demo.service.MvService;

@Controller
@RequestMapping("/mv")
public class MvController {
	@Autowired
	private MvService mvService;
	@RequestMapping("/getList")
	public String getList(Model model) {
		List<MV> getlist=mvService.getMvList();
		model.addAttribute("getlist", getlist);
		return "/user/ht_mv";
	}
	@RequestMapping("/searchMvList")
	public String searchMvList(Model model,String mv_name) {
		List<MV> getlist=mvService.searchMvList(mv_name);
		model.addAttribute("getlist",getlist);
		return "/user/ht_mv";
	}
	@RequestMapping("/addMv")
	public String addMv(MV mv,Model model) {
		int i=mvService.addMv(mv);
		if(i==0) {
			model.addAttribute("result","yes");
			model.addAttribute("msg","恭喜您，注册成功！");
		}else if(i==1) {
			model.addAttribute("result","no");
			model.addAttribute("msg","恭喜您，该用户也注册，请更换！");
		}else if(i==2) {
			model.addAttribute("result","no");
			model.addAttribute("msg","对不起，注册失败！");
		}
		return"forward:/mv/getList";
	}
	@RequestMapping("/deleteMv")
	public String deleteMv(MV mv,Model model) {
		boolean f=mvService.deleteMv(mv);
		if(f) {
			return "forward:/mv/getList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","删除失败");
			return "/user/result";	
		}
	}
}
